// pages/search/search.js
const api = require('../../config/api.js');
import { getSearch } from '../../utils/paging'

Page({

  /**
   * 页面的初始数据
   */
  data: {
    TimeId: null,
    value: '',
    report: {
      list: [],
    },

  },
  onLoad() {
    // searchBar();
    // this.getSearch();
    // console.log(this.data.report.list.length);
    // this.setData({
    //   imageShow: this.data.report.list.length
    // })
  },
  //  输入框的值发生变化就会触发事件
  inputChange(event) {
    // 1.获取输入框的值
    console.log(event.detail);
    let keyword = event.detail
    // 2.检测值合法
    if (!keyword.trim()) {
      // 终止
      return;
    }
    // 3.准备发送请求数据
    clearTimeout(this.data.TimeId)
    this.data.TimeId = setTimeout(() => {
      // 这是请求的函数
      this.getSearch(keyword)
    }, 500)

  },
  //获取项目列表
  getSearch(keyword) {
    getSearch(api.project_list, keyword, 'get').then(res => {
      this.setData({
        //小程序不支持a.b的这种赋值 
        ['report.list']: res.data.list,
      })
      for (let i = 0; i < res.data.list.length; i++) {

        switch (res.data.list[i].orderNumber) {
          case 1:
            this.setData({
              [`report.list[${i}].orderNumber`]: '待受理',
              [`report.list[${i}].orderColor`]: 'qita',
              orderColor: 'qita'
            })
            break;
          case 2:
            this.setData({
              [`report.list[${i}].orderNumber`]: '已受理',
              [`report.list[${i}].orderColor`]: 'qita',
              orderColor: 'qita'
            })
            break;
          case 3:
            this.setData({
              [`report.list[${i}].orderNumber`]: '现地勘察',
              [`report.list[${i}].orderColor`]: 'qita',
              orderColor: 'qita'
            })
            break;
          case 4:
            this.setData({
              [`report.list[${i}].orderNumber`]: '设计测算',
              [`report.list[${i}].orderColor`]: 'qita',
              orderColor: 'qita'
            })
            break;
          case 5:
            this.setData({
              [`report.list[${i}].orderNumber`]: '已受图纸和资质审核',
              [`report.list[${i}].orderColor`]: 'qita',
              orderColor: 'qita'
            })
            break;
          case 6:
            this.setData({
              [`report.list[${i}].orderNumber`]: '核准商定',
              [`report.list[${i}].orderColor`]: 'qita',
              orderColor: 'qita'
            })
            break;
          case 7:
            this.setData({
              [`report.list[${i}].orderNumber`]: '呈报签约',
              [`report.list[${i}].orderColor`]: 'qita',
              orderColor: 'qita'
            })
            break;
          case 8:
            this.setData({
              [`report.list[${i}].orderNumber`]: '施工割接',
              [`report.list[${i}].orderColor`]: 'qita',
              orderColor: 'qita'
            })
            break;
          case 9:
            this.setData({
              [`report.list[${i}].orderNumber`]: '项目完成',
              [`report.list[${i}].orderColor`]: 'wancheng',
              orderColor: 'wancheng'
            })
            break;
          case 10:
            this.setData({
              [`report.list[${i}].orderNumber`]: '驳回',
              [`report.list[${i}].orderColor`]: 'duohui',
              orderColor: 'duohui'
            })
            break;

        }

      }

    })
  },
  //跳转到详情
  goProjectDetail(e) {
    console.log(e);
    const id = e.currentTarget.dataset.id;
    const orderNumber = e.currentTarget.dataset.ordernumber
    wx.navigateTo({
      url: '/pages/project_detail/project_detail?id=' + id + '&orderNumber=' + orderNumber
    })
  },
})